Skip to main content

How to modify the rect of the camera by script using Java

How to modify the rect of the Camera by script using Java


In your Java class, do the following:

public class YourClass extends Component {

// value to control the position and size of the Camera rect
public float value = 0.5f; // select in properties

// value to control the Camera rendering layer
public int layer = 0; // select in properties

// creates a new SUIButton
public SUIButton button; // select in properties

// creates a new Camera
public Camera camera; // select in properties

@Override
public void start() {

}

@Override
public void repeat() {

// checking if the button was pressed
if (button.isDown()) {

// changing the Camera rendering layer if the conditional is true
camera.setLayer(layer);

// changing the X position of the Camera rect if the conditional is true
camera.setRectPosX(value);

// changing the Y position of the Camera rect if the conditional is true
camera.setRectPosY(value);

// changing the width of the Camera rect if the conditional is true
camera.setRectWidth(value);

// changing the height of the Camera rect if the conditional is true
camera.setRectHeight(value);
}
}
}